html 修改iframe,javascript – 如何将HTML内容设置为iframe

您所在的位置:网站首页 iframe 设置编码 html 修改iframe,javascript – 如何将HTML内容设置为iframe

html 修改iframe,javascript – 如何将HTML内容设置为iframe

2023-08-30 17:48| 来源: 网络整理| 查看: 265

我有一个HTML字符串

我想使用JavaScript将其设置为iframe。我试图设置这样的HTML:

contentWindow.document.body.innerHTML

要么

contentDocument.body.innerHTML

要么

document.body.innerHTML

但IE提供“访问被拒绝”。或“对象不支持此属性或方法”。或“操作的最终元素无效”。错误。

这是我的完整代码:

$(document).ready(function(){

var htmlString = "

Hello world";

var myIFrame = document.getElementById('iframe1');

// open needed line commentary

//myIFrame.contentWindow.document.body.innerHTML = htmlString;

//myIFrame.contentDocument.body.innerHTML = htmlString;

//myIFrame.document.body.innerHTML = htmlString;

//myIFrame.contentWindow.document.documentElement.innerHTML = htmlString;

});

This is iframe:

Your browser does not support iframes.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3